package com.agriculture.filter;

import com.agriculture.common.BaseContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component
@Slf4j
public class LoginCheckInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        String RequeatId = request.getParameter("user");
        Long id = Long.parseLong(RequeatId);
        if (id == null) {
            id = (Long) request.getSession().getAttribute("user");
        }
        log.error("拦截的 id :" + id);
        BaseContext.setCurrentId(id);
        return true;
    }

}
